import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:syn_4s/core/extension/int_extension.dart';

import '../../core/model/short_model.dart';

class MyDropDown extends StatelessWidget {
  final EdgeInsetsGeometry? margin;
  final EdgeInsetsGeometry? padding;
  final double? height;
  final double? maxHeight;
  final PopupMenuItemSelected<ShortModel>? onSelected;
  final List<ShortModel> data;
  final ShortModel? checkValue;
  final RxString content;
  final double? fontSize;

  const MyDropDown(this.data, this.content,
      {super.key,
      this.checkValue,
      this.margin,
      this.padding,
      this.height,
      this.onSelected,
      this.maxHeight,
      this.fontSize});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      margin: margin,
      padding: padding,
      height: height ?? 40.px,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(24.px)),
      ),
      child: LayoutBuilder(builder: (ctx, constraints) {
        double dropWidth = constraints.maxWidth;
        return PopupMenuButton<ShortModel>(
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(4.px),
          ),
          color: Colors.white,
          constraints: BoxConstraints(
              minWidth: dropWidth,
              maxWidth: dropWidth,
              maxHeight: maxHeight ?? double.infinity),
          position: PopupMenuPosition.under,
          onSelected: onSelected,
          itemBuilder: (BuildContext context) {
            return data.map((value) {
              return PopupMenuItem<ShortModel>(
                value: value,
                child: Text(value.name ?? ""),
              );
            }).toList();
          },
          child: Row(
            children: [
              Expanded(
                child: Obx(() => Text(
                      content.value,
                      style: TextStyle(
                          color: Colors.black, fontSize: fontSize ?? 14.px),
                    )),
              ),
              Icon(Icons.arrow_drop_down)
            ],
          ),
        );
      }),
    );
  }
}
